<!-- 详情 -->
<template>
  <div class="drawer-layout">
    <el-drawer
      :title="detailTitle"
      :visible.sync="drawer"
      @closed="closedinvitation"
      size="60%"
      :wrapperClosable="false"
    >
      <div class="layout" style="position: relative" v-loading="loading">
        <div
          class="info-box"
          style="display: flex; justify-content: space-between"
        >
          <div>
            <div style="display: flex; margin-bottom: 20px">
              <el-image
                :src="data.user.avatar"
                style="height: 50px; width: 50px; border-radius: 50px"
              ></el-image>
              <div style="margin-left: 20px; line-height: 26px">
                <div style="font-size: 14px">{{ data.user.nickname }}</div>
                <div class="idbox">ID:1234566</div>
              </div>
              <div
                style="margin-left: 40px; line-height: 25px; font-size: 14px"
              >
                <div>联系方式：{{ data.user.mobile }}</div>
                <!-- <div>
                  实名状态：
                  <span style="color: #67c23a">已实名</span>
                  <span style="color: #F56C6C;">未实名</span>
                </div> -->
              </div>
            </div>
          </div>
          <div style="font-size: 14px">
            审核状态：
            <span
              v-if="data.audit_status == 0"
              style="color: #e6a23c; font-weight: 600"
              >待审核</span
            >
            <span
              v-else-if="data.audit_status == 1"
              style="color: #67c23a; font-weight: 600"
              >审核通过</span
            >
            <span
              v-else-if="data.audit_status == 2"
              style="color: #f56c6c; font-weight: 600"
              >审核驳回</span
            >
          </div>
        </div>
        <div class="blockquote-box">充值信息</div>
        <div class="info-box">
          <div style="display: flex">
            <div class="infodiv">
              <div>充值方式：{{ data.type_name }}</div>
              <div>充值金额：￥{{ data.amount }}</div>
              <div>充值单号：{{ data.order_no }}</div>
              <div>三方单号：无</div>
            </div>
            <div class="infodiv">
              <div>充值时间：{{ data.created_at }}</div>
              <div style="display: flex">
                充值凭证：
                <el-image
                  :src="data.proof"
                  :preview-src-list="[data.proof]"
                  style="width: 120px; height: 80px; border-radius: 4px"
                ></el-image>
                <!-- 无 -->
              </div>
            </div>
          </div>
        </div>
        <div class="blockquote-box" v-if="data.audit_status == 0">
          充值审核信息
        </div>
        <el-form
          v-loading="loading"
          class="search-form"
          label-position="right"
          label-width="80px"
          size="small"
          ref="searchForm"
          :model="searchForm"
          :rules="searchRule"
        >
          <el-form-item
            label="审核状态"
            class="search-form-item"
            prop="audit_status"
          >
            <el-radio-group
              v-if="data.audit_status == 0"
              v-model="searchForm.audit_status"
            >
              <el-radio
                v-for="(item, index) in checkstatus"
                :key="index"
                :label="item.id"
                >{{ item.name }}</el-radio
              >
            </el-radio-group>
            <div v-else>
              <el-tag v-if="data.audit_status == 1" type="success"
                >已通过</el-tag
              >
              <el-tag v-else type="danger">已驳回</el-tag>
            </div>
          </el-form-item>
          <el-form-item label="审核备注" class="search-form-item" prop="remark">
            <el-input
              v-if="data.audit_status == 0"
              type="textarea"
              :rows="5"
              placeholder="请输入内容"
              v-model="searchForm.remark"
            ></el-input>
            <span v-else>
              {{ data.remark ? data.remark : "-" }}
            </span>
          </el-form-item>
        </el-form>
        <div
          style="display: flex; justify-content: center; margin: 20px"
          v-if="data.audit_status == 0"
        >
          <el-button :loading="loading" type="primary" @click="save()"
            >保存</el-button
          >
        </div>
      </div>
    </el-drawer>
  </div>
</template>
<script>
// 引入
import { list, audit } from "@/api/finance/index";
import LogoUpload from "@/components/FileUpload";
export default {
  name: "detail",
  props: ["detailTitle", "data"],
  components: {
    LogoUpload,
  },
  data() {
    return {
      loading: false,
      id: "",
      drawer: true,
      detailtitle: "",
      activeName: "first",
      searchForm: {
        id: "",
        audit_status: "",
        remark: "",
      },
      checkstatus: [
        { name: "通过", id: 1 },
        { name: "驳回", id: 2 },
      ],
      searchRule: {
        audit_status: [
          { required: true, message: "审核状态必填", trigger: "blur" },
        ],
        remark: [
          {
            required: false,
            validator: (rule, value, callback) => {
              if (this.searchForm.audit_status == 2) {
                if (value == "" || !value) {
                  callback(new Error("请输入驳回原因"));
                } else {
                  callback();
                }
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
      },
      status: "待审核",
    };
  },
  mounted() {},
  methods: {
    // 关闭添加抽屉
    closedinvitation() {
      this.$parent.closedetail();
    },
    save() {
      this.$refs.searchForm.validate((valid) => {
        if (valid) {
          this.$confirm("请仔细核对当前信息，仔细核对哦！", "确认操作", {
            confirmButtonText: "我已核对",
            cancelButtonText: "我再看看",
            type: "success",
          })
            .then(async () => {
              this.loading = true;
              this.searchForm.id = this.data.id;
              const res = await audit(this.searchForm);
              const { code, msg } = res;
              if (code === 200) {
                // 更新数据
                this.loading = false;
                this.data.audit_status = this.searchForm.audit_status;
                this.data.remark = this.searchForm.remark;
                this.$messages.success(res.msg);
              } else {
                this.loading = false;
                this.$message.error(msg);
              }
            })
            .catch(() => {});
        } else {
        }
      });
    },
  },
};
</script>
<style lang="scss">
.drawer-layout {
  /*1.显示滚动条：当内容超出容器的时候，可以拖动：*/
  .el-drawer__body {
    overflow: auto;
  }

  /*2.隐藏滚动条，太丑了*/
  .el-drawer__container ::-webkit-scrollbar {
    display: none;
  }

  .el-drawer__header {
    background-color: #409eff;
    color: #ffffff;
    padding: 10px 20px;
    margin-bottom: 10px;
  }

  .el-tabs--card {
    height: calc(100vh - 110px);
    /* overflow-y: auto; */
  }

  .el-tab-pane {
    height: calc(100vh - 110px);
    overflow-y: auto;
  }

  .el-tabs__header {
    padding-left: 50px;
    margin: 0;
  }

  .el-tabs__item {
    padding: 0 40px;
  }

  .el-tabs__nav-wrap::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background-color: #ffffff;
    z-index: 1;
  }

  .el-alert--warning.is-light .el-alert__description {
    color: #c77b04;
    font-size: 14px;
  }

  .form-box-item {
    .el-form-item__label {
      font-size: 14px !important;
      font-weight: 500;
      // width: 96px;
    }
  }
}
</style>
<style lang="scss" scoped>
.blockquote-box {
  border-left: 4px solid #409eff;
  padding-left: 16px;
  margin: 16px 0;
  height: 40px;
  line-height: 40px;
  background: #fafafa;
  font-size: 16px;
}

.info-box {
  margin: 0 20px 20px 20px;
}

.infodiv {
  color: #626262;
  font-size: 14px;
  width: 50%;

  div {
    margin-bottom: 20px;
  }
}

.idbox {
  font-size: 14px;
}

.search-form {
  margin: 0 20px;
}
</style>